import java.util.StringTokenizer;

class P498_39643 {

    public static void main(String[] args) {
    	String line = readLn();
    	
    	while (line != null) {
    		process(line);
    		
    		line = readLn();
    	}
    }

    private static void process(String line) {
		StringTokenizer st = new StringTokenizer(line);
		long[] c = new long[st.countTokens()];
		
		for (int k = 0; k < c.length; k++) {
			c[k] = Long.parseLong(st.nextToken());
		}
		
		st = new StringTokenizer(readLn());
		
		long[] x = new long[st.countTokens()];
		
		for (int k = 0; k < x.length; k++) {
			x[k]= Long.parseLong(st.nextToken());
		}
		
		StringBuffer answer = new StringBuffer();
		
		int m = x.length;
		for (int k = 0; k < m; k++) {
			long value = 0;
			int n = c.length;
			for (int i = 0; i <  n; i++) {
//				System.out.print(c[i] + "+ (" + x[k] + ")^" + (value - i)  + " +");
				value = value + c[i] * (long)Math.pow(x[k], n - i - 1); 
			}
//			System.out.println();
			answer.append(value + " "); 
		}
		
		System.out.println(answer.toString().trim());
		
		
		
		
	}

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString()).trim();
    }

}